package com.sinochem.yunlian.ship.common.util;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.List;
import java.util.Set;

/**
 * @Auther: zzd
 * @Dscription: List集合操作类
 * @Date: Create in 2017/12/7 21:19
 **/
public class ListUtils {

    /**
     *  big和small的差集
     *    例如：
     *    A = {"2","3","4","5"}
     *    B = {"1", "2", "3", "10"}
     *    getDiffFromSmall(A,B) ==> [4, 5]
     * @param big
     * @param small
     * @return
     */
    public static List<String> getDiff(List<String> big, List<String> small) {
        Set<String> differenceSet = Sets.difference(Sets.newHashSet(big), Sets.newHashSet(small));
        return Lists.newArrayList(differenceSet);
    }

    /**
     *   big和small的交集
     *    例如：
     *    A = {"2","3","4","5"}
     *    B = {"1", "2", "3", "10"}
     *    getIntersection(A,B) ==> [2, 3]
     * @param big
     * @param small
     * @return
     */
    public static List<String> getIntersection(List<String> big,List<String> small){
        Set<String> intersectionSet = Sets.intersection(Sets.newHashSet(big), Sets.newHashSet(small));
        return  Lists.newArrayList(intersectionSet);
    }


}
